package com.Controller.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sql.DAO;

import com.Model.Date.DateTime;
import com.Model.Pojo.Users;

public class ShenQingXinYongKa extends HttpServlet {

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
    	response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
    	HttpSession session = request.getSession(false);
    	Users  user = (Users)session.getAttribute("users");
    	String zhanghao = user.getZhanghao();
    	String name = user.getXingming();
		String leixing = request.getParameter("leixing");
		if(leixing.equals("putongka")){
			leixing = "普通卡";
		}else if(leixing.equals("jinka")){
			leixing = "金卡";
		}else if(leixing.equals("daijika")){
			leixing = "贷记卡";
		}else if(leixing.equals("zhundaijika")){
			leixing = "准贷记卡";
		}
		String realname = request.getParameter("name");
		String shenfenzhenghao = request.getParameter("shenfenzhenghao");
		String pass = request.getParameter("password");
		DateTime date = new DateTime();
		String sql = "insert into CreditCard (accountNumber,name,type,realName,idNumber,pass,date)value(" +
				"'" + zhanghao + "','" + name + "','" + leixing + "','" + realname + "','" + shenfenzhenghao + "','" + pass + "','" + date.getSettime() + "')";
		DAO dao = new DAO();
		dao.zengjia(sql);
		response.sendRedirect("/Bank/WebPage/FrontPage/CreditCardPage/CreditCardsList.jsp");
		out.flush();
		out.close();
	}

}
